package com.macro.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.macro.mall.dto.e.ReportTotalEntDTO;
import com.macro.mall.dto.o.ReportTotalOutDTO;
import com.macro.mall.mapper.RpsTotalResultMapper;
import com.macro.mall.model.RpsTotalResult;
import com.macro.mall.service.ReportTotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ReportTotalServiceImpl implements ReportTotalService {
    @Autowired
    private RpsTotalResultMapper rpsTotalResultMapper;

    @Override
    public PageInfo<ReportTotalOutDTO> list(ReportTotalEntDTO reportTotalEntDTO) {
        PageHelper.startPage(reportTotalEntDTO.getPage(),reportTotalEntDTO.getPageSize());
        List<RpsTotalResult> list = rpsTotalResultMapper.list(reportTotalEntDTO.getDateType());
        PageInfo<RpsTotalResult> rpsTotalResultPageInfo = new PageInfo<>(list);
        List<ReportTotalOutDTO> list1 =new ArrayList<>();
        for (RpsTotalResult rpsTotalResult:list){
            ReportTotalOutDTO reportTotalOutDTO = new ReportTotalOutDTO();
            reportTotalOutDTO.setId(rpsTotalResult.getId());
            reportTotalOutDTO.setStatus(rpsTotalResult.getStatus());
            reportTotalOutDTO.setType(rpsTotalResult.getType());
            reportTotalOutDTO.setDateType(rpsTotalResult.getDataType());
            reportTotalOutDTO.setCount(rpsTotalResult.getCount());
            reportTotalOutDTO.setCreatedDt(rpsTotalResult.getCreatedDt());
            list1.add(reportTotalOutDTO);
        }
        PageInfo<ReportTotalOutDTO> reportTotalOutDTOPageInfo = new PageInfo<>(list1);
        reportTotalOutDTOPageInfo.setTotal(rpsTotalResultPageInfo.getTotal());
        return reportTotalOutDTOPageInfo;
    }

    @Override
    public int modify(ReportTotalEntDTO reportTotalEntDTO) {
        RpsTotalResult rpsTotalResult = new RpsTotalResult();
        rpsTotalResult.setId(reportTotalEntDTO.getId());
        rpsTotalResult.setType(reportTotalEntDTO.getType());
        rpsTotalResult.setDataType(reportTotalEntDTO.getDateType());
        rpsTotalResult.setCount(reportTotalEntDTO.getCount());
        return rpsTotalResultMapper.updateByPrimaryKeySelective(rpsTotalResult);
    }
}
